<template>
    <div style="margin-top: 20px; height: 300px;">
      <Chart :height="height" :option="chartOption" />
    </div>
  </template>
  
  <script setup>
  import Chart from "@/components/charts/index.vue";
  import useChartOption from '@/hooks/charts';
  import { storeToRefs } from "pinia";
  import { useAppStore } from '@/pinia';
  
  // 定义颜色数组
  const colors = ['#0065ff', '#ff6f61'];
  
  const appStore = useAppStore();
  const { config } = storeToRefs(appStore);
  
  const props = defineProps({
    height: {
      type: String,
      default: '300px',
    },
    data: {
      type: Array,
      default: () => []
    }
  });
  
  const { chartOption } = useChartOption(() => {
    return {
      tooltip: {
        trigger: 'item',
        formatter: '{b}: {c} ({d}%)'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          name: '数据',
          type: 'pie',
          radius: ['60%', '100%'],
          data: props.data.slice(0, 2).map((item, index) => ({
            name: item.name,
            value: item.value,
            extraField1: item.extraField1,
            extraField2: item.extraField2,
            itemStyle: { color: colors[index % colors.length] } // 使用颜色数组
          })),
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          },
          label: {
            normal: {
              formatter: '{b}: {c} ({d}%)\n',
              position: 'outside'
            }
          },
          labelLine: {
            normal: {
              length: 10,
              length2: 10,
              smooth: true,
              lineStyle: {
                width: 0
              }
            }
          },
          itemStyle: {
            borderWidth: 0
          }
        }
      ]
    };
  });
  </script>
  
  <style scoped lang="scss">
  </style>